-- SealRoom
-- Created by huanghr July/14/2016
-- 封印的房间

-- 初始化
function initSealRoom(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local dbase = DungeonM.query(class, "dbase");
    local sealItemId  = dbase["seal_item"];
    if type(sealItemId) ~= "table" then
        error("没有配置解除封印所需的物品。");
        return;
    end

    local buildingInfo = BuildingBonusM.queryBuildingView(class);
    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 音效
            AudioM.playFx("workshop_open_ui");

            local pos = self.gridData:getPos();

            -- 解除封印
            local function okFunc()
                DungeonActionM.go("unlock_sealroom", pos);
            end

            self:openBuildingView(okFunc);
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end

-- 封印的房间
function onShowcaseUnlock(self)
    alert(getLocStr("unlock_seal_room"));

    -- 播放封印解除的光效
    local function playUnlockEffect()
        playEffect(self, 1261, -18, 140, nil, 1.3);
        playEffect(self, 1262, -20, 120, nil, 1.3);
    end
    performWithDelay(self, playUnlockEffect, 0.5);
end
